<?php
namespace app\model;

use think\Model;

class Expand extends Model
{
	protected $table = 'cfg_expand';

	public static function getList ( array $array, int $type ) {
		$where = [];
		array_push($where, ['companyId', '=', $array['companyId']]);
		array_push($where, ['userType', '=', $type]);
		$query = self::field('id, username, userid, bazaarId, contact, customerid, status')->where($where)->select()->toArray();
		return $query;
	}

	public static function getAuthList ( array $array, int $type ) {
		$where = [];
		array_push($where, ['companyId', '=', $array['companyId']]);
		array_push($where, ['userType', '=', $type]);
		$user = new User;
		$roleTempId = $user->where('id', $array['id'])->value('role');
		if($roleTempId) {
			$role = new Role;
			if( $type == 1 ) {
				$authaccount = $role->where('id', $roleTempId)->value('semauthaccount');
			} else {
				$authaccount = $role->where('id', $roleTempId)->value('feedauthaccount');
			}
			if($authaccount) {
				array_push($where, ['userid', 'in', $authaccount]);
			}
		}
		$query = self::field('id, username, userid, bazaarId, contact, customerid, status')->where($where)->select()->toArray();
		return $query;
	}

	public static function getUserInfo (array $array, int $userId, int $type ) {
		$where = [];
		array_push($where, ['companyId', '=', $array['companyId']]);
		array_push($where, ['userId', '=', $userId]);
		array_push($where, ['userType', '=', $type]);
		$row = self::where($where)->find();
		if(empty($row)) {
			return false;
		}
		return $row;
	}

}